<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    // 统计字符串中每种字符出现的次数,出现次数最多的是？ 出现？次
// hash  
    var str = "helloworld";
    for (var i = 0, hash = {}; i < str.length; i++) {
        if (hash[str[i]]) {
            hash[str[i]]++
        } else {
            hash[str[i]] = 1;
        }
    }
    console.dir(hash);

// 正则     
    var s = "helloworld";
    var arr = s.split("")
        .join("")
        .match(/([a-z])\1*/g)
        .sort(function (a, b) {
            return b.length - a.length;
        })
    console.log("出现最多的是: " + arr[0][0] + "共" + arr[0].length + "次");
    var hash = {};
    arr.forEach(function (val) {
        hash[val[0]] = val.length;
    });
    console.dir(hash);

</script>